package com.empire.module.sporttery.controller.app.football;

import com.empire.module.member.api.user.MemberUserApi;
import com.empire.module.spider.api.FootballMatchSportteryApi;
import com.empire.module.spider.api.dto.FootballMatchSportteryDTO;
import com.empire.module.sporttery.convert.footballmatch.FootballMatchConvert;
import com.empire.module.sporttery.vo.FootballDayResultVO;
import com.empire.module.sporttery.vo.FootballVO;
import com.empire.module.sporttery.vo.GuoguanVO;
import com.empire.module.sporttery.vo.MatchBonusItemVO;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.empire.framework.common.pojo.PageParam;
import com.empire.framework.common.pojo.PageResult;
import com.empire.framework.common.pojo.CommonResult;
import com.empire.framework.common.util.object.BeanUtils;
import static com.empire.framework.common.pojo.CommonResult.success;

import com.empire.framework.excel.core.util.ExcelUtils;

import com.empire.framework.apilog.core.annotation.ApiAccessLog;
import static com.empire.framework.apilog.core.enums.OperateTypeEnum.*;

import com.empire.module.sporttery.controller.app.football.vo.*;
import com.empire.module.sporttery.dal.dataobject.footballmatch.FootballMatchDO;
import com.empire.module.sporttery.service.footballmatch.FootballMatchService;

@Tag(name = "用户 APP - 竞猜足彩比赛")
@RestController
@RequestMapping("/sporttery/app/football-match")
@Validated
public class AppFootballMatchController {

    @Resource
    private FootballMatchService footballMatchService;

    @Resource
    private FootballMatchSportteryApi footballMatchSportteryApi;

    @GetMapping("/get")
    @Operation(summary = "获得竞猜足彩比赛")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppFootballMatchRespVO> getFootballMatch(@RequestParam("id") Integer id) {
        FootballMatchDO footballMatch = footballMatchService.getFootballMatch(id);
        return success(BeanUtils.toBean(footballMatch, AppFootballMatchRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得竞猜足彩比赛分页")
    public CommonResult<PageResult<AppFootballMatchRespVO>> getFootballMatchPage(@Valid AppFootballMatchPageReqVO pageReqVO) {
        PageResult<FootballMatchDO> pageResult = footballMatchService.getFootballMatchPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppFootballMatchRespVO.class));
    }

    @PostMapping("/getDayResults")
    @Operation(summary = "获得足球竞猜每天的命中统计")
    public CommonResult<List<FootballDayResultVO>> getDayResults(@RequestBody AppFootballMatchPageReqVO pageReqVO) {
        List<FootballDayResultVO> pageResult = footballMatchService.getDayResults(pageReqVO);
        return success(pageResult);
    }

    @PostMapping("/getByDay")
    @Operation(summary = "获得某一日期的竞猜足彩比赛")
    public CommonResult<List<AppFootballMatchRespVO>> getByDay(@RequestBody AppFootballMatchPageReqVO pageReqVO) {
        List<FootballMatchDO> footballMatchs = footballMatchService.getFootballMatchByDay(pageReqVO);
        return success(BeanUtils.toBean(footballMatchs, AppFootballMatchRespVO.class));
    }

    @GetMapping("/list")
    @Operation(summary = "获得list")
    public CommonResult<List<FootballMatchDO>> getList() {
        List<FootballMatchDO> footballMatchs = footballMatchService.getMatchs();
        return success(footballMatchs);
    }

    @GetMapping("/getSellingMatchs")
    @Operation(summary = "获得当天及以后未开奖的比赛")
    public CommonResult<List<AppFootballMatchSportteryRespVO>> getSellingMatchList(@RequestParam("type") Integer type) {
        List<FootballMatchSportteryDTO> footballMatchs = footballMatchSportteryApi.getSellingMatchList();
        List<AppFootballMatchSportteryRespVO> list = FootballMatchConvert.INSTANCE.convertList(footballMatchs,type);
        return success(list);
    }

    @PostMapping("/calculateBonus")
    @Operation(summary = "计算奖金")
    public CommonResult<AppFootballBuySchemeRespVO> calculateBonus(@RequestBody @Valid AppFootballCalculateBonusReqVO vo) {
        List<FootballMatchSportteryDTO> mlist = footballMatchSportteryApi.getSellingMatchList();
        List<MatchBonusItemVO> list = FootballMatchConvert.INSTANCE.convertList3(mlist);
        AppFootballBuySchemeRespVO result = footballMatchService.calculateBonus(vo,list);
        return success(result);
    }

}